<?
    require_once('funcs.php');

    //definitions
    $filename = '.menu';

    //get script location
    /*
    $scriptname = script_name();
    */
    $scriptname = '/about/ggb/';
    $path = root_path();

    $path_parts = split_path($scriptname);

    //read main menu
    $lines = @file("$path/$filename");
    if (!$lines) $lines = array();
    $part = array_shift($path_parts);
    $i = 0;
    foreach ($lines as $line)
    {
        switch ($i) {
        case 0:
            $menuitem['name'] = trim($line);
            break;
        case 1:
            $menuitem['href'] = trim($line);
            break;
        case 2:
            $menuitem['title'] = trim($line);
            $menuitem['selected'] = contains($menuitem['href'], $part);
            $menuitem['anchor'] = !endsWith($scriptname, $menuitem['href']);
            $upmenu[] = $menuitem;
            break;
        }
        $i = ($i + 1) % 3;
    }
    //mark first and last elements
    $upmenu[0]['first'] = TRUE;
    $upmenu[count($upmenu) - 1]['last'] = TRUE;

    //read uplevel menu
    $path .= "/$part";
    $lines = @file("$path/$filename");
    if (!$lines) $lines = array();
    $part = array_shift($path_parts);
    $i = 0;
    foreach ($lines as $line)
    {
        switch ($i) {
        case 0:
            $menuitem['name'] = trim($line);
            break;
        case 1:
            $menuitem['href'] = trim($line);
            break;
        case 2:
            $menuitem['title'] = trim($line);
            $menuitem['selected'] = contains($menuitem['href'], $part);
            $menuitem['anchor'] = !endsWith($scriptname, $menuitem['href']);
            $menu[] = $menuitem;
            break;
        }
        $i = ($i + 1) % 3;
    }
    //mark first and last elements
    $menu[0]['first'] = TRUE;
    $menu[count($menu) - 1]['last'] = TRUE;

?>